﻿@using EC.Models 
@using EcBlog.Data
@using EcBlog.Extensions
@using EcBlog.Models
@{ 
    if(((RazorView)this.ViewContext.View).LayoutPath == "~/Areas/Admin/Views/Shared/_InstallLayout.cshtml" )
    {
        return;
    }
    object layout;
    if (this.ViewContext.ViewData.ModelMetadata == null || this.ViewContext.ViewData.ModelMetadata.Properties.All(c => c.PropertyName != "Layout"))
    {
        var unitOfWork = DependencyResolver.Current.GetService<IEcUnitOfWork>();
        var siteSettings = unitOfWork.SiteSettingRepository;
        var defaultLayoutName = siteSettings[SiteSettingKey.DefaultLayoutName];
        var defaultLayout = unitOfWork.LayoutRepository.Get().First(c => c.Name == defaultLayoutName);
        layout = defaultLayout;
    }
    else
    {
        layout = this.ViewContext.ViewData.ModelMetadata.Properties.First(c => c.PropertyName == "Layout").Model;
    }
    Layout = ((Layout)layout).LayoutPath;
}